import mockApi from "@/api/mockApi";
import type {SkillCertificateForm} from '@/types/req/skillCertificateForm'
import type {SkillCertificateQueryForm} from '@/types/req/skillCertificateQueryForm'
import type {SkillCertificate} from '@/types/resp/skillCertificate'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";
import dayjs from "dayjs";

export default class skillCertificateApi {
  static skillCertificates: SkillCertificate[] = [
    {"id":1,"candidateId":3,"candidateName":"张伟","certificateName":"PMP项目管理专业人士认证","issuingAuthority":"PMI（项目管理协会）","issueDate":dayjs("2020-05-15"),"expiryDate":dayjs("2023-05-15"),"createTime":"2024-02-27 22:24:15","modifyTime":"2024-03-23 22:24:15"},{"id":2,"candidateId":4,"candidateName":"陈静","certificateName":"Scrum Master认证","issuingAuthority":"Scrum Alliance","issueDate":dayjs("2019-08-10"),"expiryDate":dayjs("2022-08-10"),"createTime":"2024-10-04 22:24:15","modifyTime":"2024-07-21 22:24:15"},
    {"id":3,"candidateId":2,"candidateName":"陈静","certificateName":"AWS解决方案架构师认证","issuingAuthority":"亚马逊云科技（AWS）","issueDate":dayjs("2021-03-20"),"expiryDate":dayjs("2024-03-20"),"createTime":"2024-08-17 22:24:15","modifyTime":"2024-01-16 22:24:15"},
    {"id":4,"candidateId":3,"candidateName":"张伟","certificateName":"Oracle认证数据库专家","issuingAuthority":"Oracle公司","issueDate":dayjs("2018-11-01"),"expiryDate":dayjs("2021-11-01"),"createTime":"2024-02-07 22:24:15","modifyTime":"2024-06-28 22:24:15"},
    {"id":5,"candidateId":2,"candidateName":"陈静","certificateName":"Google数据分析师认证","issuingAuthority":"Google","issueDate":dayjs("2022-06-05"),"expiryDate":dayjs("2025-06-05"),"createTime":"2024-01-15 22:24:15","modifyTime":"2024-10-19 22:24:15"},
    {"id":6,"candidateId":1,"candidateName":"王强","certificateName":"Cisco认证网络工程师","issuingAuthority":"Cisco","issueDate":dayjs("2017-09-12"),"expiryDate":dayjs("2020-09-12"),"createTime":"2024-02-15 22:24:15","modifyTime":"2024-04-11 22:24:15"},
    {"id":7,"candidateId":3,"candidateName":"张伟","certificateName":"微软Azure解决方案架构师认证","issuingAuthority":"微软","issueDate":dayjs("2023-02-10"),"expiryDate":dayjs("2026-02-10"),"createTime":"2024-12-08 22:24:15","modifyTime":"2024-06-21 22:24:15"}
  ]

  static async save (skillCertificateForm: SkillCertificateForm): Promise<Result<void>> {
    console.log('skillCertificateApi save params', skillCertificateForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (skillCertificateQueryForm: SkillCertificateQueryForm): Promise<Result<Page<SkillCertificate>>> {
    console.log('skillCertificateApi find params', skillCertificateQueryForm)
    let filteredSkillCertificates = skillCertificateApi.skillCertificates
    if (skillCertificateQueryForm.candidateId) {
      filteredSkillCertificates = skillCertificateApi.skillCertificates.filter(skillCertificate => skillCertificate.candidateId === skillCertificateQueryForm.candidateId);
    }
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(filteredSkillCertificates)
    return response.data
  }

  static async findById (id: number): Promise<Result<SkillCertificate>> {
    console.log('skillCertificateApi findById id', id)
    let target = {}
    for (const a of skillCertificateApi.skillCertificates) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<SkillCertificate> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('skillCertificateApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
